package com.android.slidingmenuexample.menuactivities;

import java.util.*;

import com.android.slidingmenuexample.ExpandableListAdapter;
import com.android.slidingmenuexample.*;

import android.app.*;
import android.content.Intent;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;

public class NoticeFragment extends Fragment
{
  
  ExpandableListAdapter listAdapter;
  ExpandableListView expListView;
  List<String> listDataHeader;
  HashMap<String, List<String>> listDataChild;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  {
    View root = inflater.inflate(R.layout.layout_fragment, container);
    
    expListView = (ExpandableListView) root.findViewById(R.id.lvExp);
    
    prepareListData();
    
    listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
    
    expListView.setAdapter(listAdapter);
    
    // Listview Group expanded listener
    expListView.setOnGroupExpandListener(new OnGroupExpandListener()
    {
      
      @Override
      public void onGroupExpand(int groupPosition)
      {
//            Toast.makeText(getApplicationContext(),
//                    listDataHeader.get(groupPosition) + " Expanded",
//                    Toast.LENGTH_SHORT).show();
      }
    });
    
    // Listview Group collasped listener
    expListView.setOnGroupCollapseListener(new OnGroupCollapseListener()
    {
      
      @Override
      public void onGroupCollapse(int groupPosition)
      {
//            Toast.makeText(getApplicationContext(),
//                    listDataHeader.get(groupPosition) + " Collapsed",
//                    Toast.LENGTH_SHORT).show();
        
      }
    });
    
    // Listview on child click listener
    expListView.setOnChildClickListener(new OnChildClickListener()
    {
      
      @Override
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
      {
//    	  Intent intent = getActivity().getIntent();
//    	  intent.putExtra("key", "key");

        // TODO Auto-generated method stub
//            Toast.makeText(
//                    getApplicationContext(),
//                    listDataHeader.get(groupPosition)
//                            + " : "
//                            + listDataChild.get(
//                                    listDataHeader.get(groupPosition)).get(
//                                    childPosition), Toast.LENGTH_SHORT)
//                    .show();
        return false;
      }
    });
    
    return root;
    
  }
  
  
  public void prepareListData()
  {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();
    
    listDataHeader.add("10학번 엠티공지");
    listDataHeader.add("우재열 군대 ㅠㅠ");
    
    List<String> seoul = new ArrayList<String>();
    seoul.add("난징캠핑장 이창희 짱짱맨");
    
    List<String> gyeonggi = new ArrayList<String>();
    gyeonggi.add("재열이 군대가ㅛㅇ ㅠㅠㅠㅠ ");

    listDataChild.put(listDataHeader.get(0), seoul);
    listDataChild.put(listDataHeader.get(1), gyeonggi);
  }  
}